package com.controller;

import com.constant.Constant;
import com.entity.Resource;
import com.entity.User;
import com.service.ResourceService;
import com.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * date:2021/5/6
 * description:
 * Author:Stargazer
 * /resource/showRs.do?course_id
 */
@Controller
@RequestMapping("/resource")
public class ResourseController {
    @Autowired
    ResourceService resourceService;

    /**
     *资源校验方法
     *验证用户积分或金币是否足够
     * 用户信息是放到session中的
     */
    public AjaxResult checkResource(@RequestParam("resource_id") Integer resourceId,@RequestParam("path") String path,
                                    HttpSession session){
        User user = (User) session.getAttribute(Constant.SESSION_USER);//通过session获取当前的user对象
        AjaxResult ajaxResult = resourceService.checkResourceByIdAndUser(resourceId, user);
        return ajaxResult;
    }

    //加载章节资源mp4视频
    @RequestMapping("/showRs.do")
    public String loadChapterResourse() {

        return "";
    }
}
